//
//  LBBaseRequest.m
//  LBNetworking
//
//  Created by WuShiHai on 19/5/30.
//  Copyright (c) 2019 Lebbay. All rights reserved.
//

#import "LBBaseRequest.h"
#import "LBRequestEncryption.h"
#import <LBFoundation/LBFoundation.h>

@implementation LBBaseRequest

+ (instancetype)defaultRequest:(NSString *)bundleVersion {
    return [self defaultRequest:bundleVersion
                         apiKey:nil
                          token:nil
                         userId:nil];
}

+ (instancetype)defaultRequest:(NSString *)bundleVersion
                        apiKey:(NSString *)apiKey
                         token:(NSString *)token
                        userId:(NSString *)userId {
    LBBaseRequest *request = [[LBBaseRequest alloc] init];
    request.session = [LBRequestSession currentSession:token
                                         userId:userId];
    request.system = [LBRequestSystem current:bundleVersion];
    request.apiKey = apiKey;
    return request;
}

- (NSDictionary *)signRequest{
    NSMutableDictionary *params = [[self yy_modelToJSON] mutableCopy];
    NSString *dataString = [self.data yy_modelToJSONString]?:@"{}";
    NSString *dataBody = [NSString stringWithFormat:@"%@%@%@%@", self.apiKey?:@"", self.session.token?:@"", dataString?:@"", @"sjdo12379341jik890879&*#@$^&*Q*&"];
    self.sign = [dataBody MD5];
    [params setObject:self.sign forKey:@"sign"];
//    [params setObject:dataString forKey:@"data"];
    return params.copy;
}

@end
